package com.guet.controller.teacher;

import com.guet.DTO.PasswordEditDTO;
import com.guet.DTO.UserDTO;
import com.guet.VO.UserVO;
import com.guet.result.Result;
import com.guet.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.annotation.RequestScope;

@RestController("teaUserController")
@RequestMapping("/teacher/user")
@Slf4j
@CrossOrigin
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 获取用户信息
     * @return
     */
    @GetMapping
    public Result<UserVO> getUserInfo() {
        UserVO userVO = userService.getUserInfo();
        return Result.success(userVO);
    }

    /**
     * 更新用户信息
     * @param userDTO
     * @return
     */
    @PostMapping
    public Result<Object> updateUserInfo(@RequestBody UserDTO userDTO) {
        log.info("userDTO: {}", userDTO);
        userService.update(userDTO);
        return Result.success();
    }

    @PostMapping("password")
    public Result<Object> updatePassword(@RequestBody PasswordEditDTO passwordEditDTO) {
        log.info("passwordEditDTO: {}", passwordEditDTO);
        userService.updatePassword(passwordEditDTO);
        return Result.success();
    }


}
